package crl.lottery.view
{
	import flash.display.DisplayObjectContainer;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import org.aswing.AsWingManager;
	
	public class LAlert extends Sprite
	{
		
		public static var container:DisplayObjectContainer;
		
		private var _skin:AlertSkin2;
		
		private var msgTF:TextField;
		private var okBtn:*;
		
		public var finishHandler:Function;
		public function LAlert()
		{
			
			this.graphics.clear();
			this.graphics.beginFill(0,0);
			
			var w:int=432;
			var h:int=530;
			this.graphics.drawRect(0,0,w,h);
			
			skin=new AlertSkin2();
			
			skin.x=(w-skin.width)>>1;
			skin.y=(h-skin.height)>>1;
			
			this.addChild(skin);
			
		}
		
		public function set skin(value:AlertSkin2):void{
			this._skin=value;
			bindComponent();
		}
		
		public function get skin():AlertSkin2{
			return this._skin;
		}
		
		protected function bindComponent():void{
			msgTF=_skin.msgTF;
			okBtn=_skin.okBtn;
			
			new LButton(okBtn);
			
			msgTF.mouseEnabled=msgTF.selectable=false;
			
			okBtn.addEventListener(MouseEvent.CLICK,clickHandler);
		}
		
		
		public function set message(value:String):void{
			this.msgTF.htmlText=value;
		}
		
		public function show():void{
			if(container==null){
				container=AsWingManager.getStage();
			}
			container.addChild(this);
		}
		
		private function clickHandler(event:Event):void{
			if(finishHandler!=null)finishHandler(1);
			if(container.contains(this))container.removeChild(this);
		}
	}
}